Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-0 vector-toc-not-available vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-0 vector-feature-night-mode-enabled skin-theme-clientpref-os vector-sticky-header-enabled" lang="fr" dir="ltr"><head>
<meta charset="UTF-8">
<title>CoffeeScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="./_res_/favicon.png">
<link rel="canonical" href="https://fr.wikipedia.org/wiki/CoffeeScript"> <link href="./_mw_/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./_mw_/ext.wikimediamessages.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./_mw_/skins.vector.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./_mw_/site.styles.css">
<link rel="stylesheet" type="text/css" href="./_mw_/noscript.css">
<link rel="stylesheet" type="text/css" href="./_res_/footer.css">
<link rel="stylesheet" type="text/css" href="./_res_/vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-CoffeeScript rootpage-CoffeeScript skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">CoffeeScript</span></h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="contentSub">
<div id="mw-content-subtitle"></div>
</div>
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="fr" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="fr" dir="ltr"><p class="mw-empty-elt">
</p>
<table class="infobox_v2 infobox infobox--frwiki noarchive">
<tbody><tr>
<td colspan="2" class="entete informatique" style="background-color:#2f2625;color:black;"><span style="color: #fff;">CoffeeScript</span><style data-mw-deduplicate="TemplateStyles:r228712691">
/* start https://fr.wikipedia.org/ */


.mw-parser-output .entete.informatique{background-image:url("./_mw_/Picto.nfo.png")}


/* end https://fr.wikipedia.org/ */
</style>
</td></tr>
<tr><td colspan="3" style="text-align:center; line-height: 1.5em;"> </td></tr>
<tr>

<td colspan="2"><hr style="height:2px; color:inherit; background-color:#2f2625;"></td></tr>
<tr>
<th scope="row">Date de première version
</th>
<td><time class="nowrap" datetime="2009-12-13" data-sort-value="2009-12-13">13 décembre 2009</time> (<span data-sort-value="&amp;0000000000005802" class="datasortkey">15&nbsp;ans, 323&nbsp;jours</span>)
</td>
</tr>
<tr>
<th scope="row"><a href="Paradigme_(programmation)" title="Paradigme (programmation)">Paradigme</a>
</th>
<td><a href="Paradigme_de_programmation" class="mw-redirect" title="Paradigme de programmation">Multi-paradigme</a>
</td>
</tr>
<tr>

<th scope="row">Auteur
</th>
<td><a href="Jeremy_Ashkenas" title="Jeremy Ashkenas">Jeremy Ashkenas</a>
</td>
</tr>
<tr>



<th scope="row"><a href="Version_d'un_logiciel" title="Version d'un logiciel">Dernière version</a>
</th>
<td><span class="wd_p348">2.7.0 (<time class="nowrap date-lien" datetime="2022-04-24" data-sort-value="2022-04-24"><a href="24_avril" title="24 avril">24</a> <a href="Avril_2022" title="Avril 2022">avril</a> <a href="2022" title="2022">2022</a></time>)<sup id="cite_ref-wikidata-8a46862771c9073d71b5485985192cedb12b4b77_1-1" class="reference"><a href="#cite_note-wikidata-8a46862771c9073d71b5485985192cedb12b4b77-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup class="reference cite_virgule">,</sup><sup id="cite_ref-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944_2-1" class="reference"><a href="#cite_note-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup></span>
</td>
</tr>
<tr>
<th scope="row"><a href="Version_d'un_logiciel" title="Version d'un logiciel">Version en développement</a>
</th>
<td><span class="wd_p348">2.0.0-alpha1 (<time class="nowrap date-lien" datetime="2017-02-22" data-sort-value="2017-02-22"><a href="22_f%C3%A9vrier" title="22 février">22</a> <a href="F%C3%A9vrier_2017" title="Février 2017">février</a> <a href="2017" title="2017">2017</a></time>)<sup id="cite_ref-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944_2-2" class="reference"><a href="#cite_note-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><br>2.0.0-beta1 (<time class="nowrap date-lien" datetime="2017-04-14" data-sort-value="2017-04-14"><a href="14_avril" title="14 avril">14</a> <a href="Avril_2017" title="Avril 2017">avril</a> <a href="2017" title="2017">2017</a></time>)<sup id="cite_ref-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944_2-3" class="reference"><a href="#cite_note-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><br>2.0.0-beta2 (<time class="nowrap date-lien" datetime="2017-05-17" data-sort-value="2017-05-17"><a href="17_mai" title="17 mai">17</a> <a href="Mai_2017" title="Mai 2017">mai</a> <a href="2017" title="2017">2017</a></time>)<sup id="cite_ref-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944_2-4" class="reference"><a href="#cite_note-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><br>2.0.0-beta3 (<time class="nowrap date-lien" datetime="2017-06-30" data-sort-value="2017-06-30"><a href="30_juin" title="30 juin">30</a> <a href="Juin_2017" title="Juin 2017">juin</a> <a href="2017" title="2017">2017</a></time>)<sup id="cite_ref-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944_2-5" class="reference"><a href="#cite_note-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><br>2.0.0-beta4 (<time class="nowrap date-lien" datetime="2017-08-04" data-sort-value="2017-08-04"><a href="4_ao%C3%BBt" title="4 août">4</a> <a href="Ao%C3%BBt_2017" title="Août 2017">août</a> <a href="2017" title="2017">2017</a></time>)<sup id="cite_ref-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944_2-6" class="reference"><a href="#cite_note-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><br>2.0.0-beta5 (<time class="nowrap date-lien" datetime="2017-09-02" data-sort-value="2017-09-02"><a href="2_septembre" title="2 septembre">2</a> <a href="Septembre_2017" title="Septembre 2017">septembre</a> <a href="2017" title="2017">2017</a></time>)<sup id="cite_ref-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944_2-7" class="reference"><a href="#cite_note-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup></span>
</td>
</tr>
<tr>
<th scope="row">Typage
</th>
<td><a href="Typage_dynamique" title="Typage dynamique">Dynamique</a>, <a href="Typage_faible" class="mw-redirect" title="Typage faible">faible</a>
</td>
</tr>
<tr>


<th scope="row">Influencé par
</th>
<td><a href="JavaScript" title="JavaScript">JavaScript</a>, <a href="Python_(langage)" title="Python (langage)">Python</a>, <a href="Ruby" title="Ruby">Ruby</a>, <a href="Haskell" title="Haskell">Haskell</a><sup id="cite_ref-changelog_3-0" class="reference"><a href="#cite_note-changelog-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>, <a href="YAML" title="YAML">YAML</a><sup id="cite_ref-smell_4-0" class="reference"><a href="#cite_note-smell-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
</td>
</tr>
<tr>
<th scope="row">A influencé
</th>
<td>MoonScript
</td>
</tr>
<tr>

<th scope="row"><a href="Langage_de_programmation" title="Langage de programmation">Écrit en</a>
</th>
<td><span class="wd_p277">CoffeeScript</span>
</td>
</tr>
<tr>
<th scope="row"><a href="Syst%C3%A8me_d'exploitation" title="Système d'exploitation">Système d'exploitation</a>
</th>
<td><a href="Multiplate-forme" class="mw-redirect" title="Multiplate-forme">Multiplate-forme</a>
</td>
</tr>
<tr>

<th scope="row"><a href="Licence_de_logiciel" title="Licence de logiciel">Licence</a>
</th>
<td><span class="wd_p275"><a href="Licence_MIT" title="Licence MIT">Licence MIT</a><sup id="cite_ref-wikidata-126859c26edb20d85933f02deb358e1e75771575Q124688_5-0" class="reference"><a href="#cite_note-wikidata-126859c26edb20d85933f02deb358e1e75771575Q124688-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup></span>
</td>
</tr>
<tr>
<th scope="row"><a href="Site_web" title="Site web">Site web</a>
</th>
<td><span class="wd_p856"><a rel="nofollow" class="external text" href="https://coffeescript.org/">coffeescript.org</a></span>
</td>
</tr>
<tr>
<th scope="row"><a href="Extension_de_nom_de_fichier" title="Extension de nom de fichier">Extension de fichier</a>
</th>
<td><span class="wd_p1195">coffee</span>
</td>
</tr>
<tr>

</tr>
</tbody></table>
<p><b>CoffeeScript</b> est un <a href="Langage_de_programmation" title="Langage de programmation">langage de programmation</a>, qui se <a href="Compilateur" title="Compilateur">compile</a> en <a href="JavaScript" title="JavaScript">JavaScript</a>. Le langage ajoute du <a href="Sucre_syntaxique" title="Sucre syntaxique">sucre syntaxique</a> inspiré par <a href="Python_(langage)" title="Python (langage)">Python</a>, <a href="Ruby" title="Ruby">Ruby</a> et <a href="Haskell" title="Haskell">Haskell</a><sup id="cite_ref-changelog_3-1" class="reference"><a href="#cite_note-changelog-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> afin d'améliorer la brièveté et la lisibilité du JavaScript, tout en ajoutant des fonctionnalités comme le <a href="Filtrage_par_motif" title="Filtrage par motif">filtrage par motif</a> ou les <a href="Liste_en_compr%C3%A9hension" title="Liste en compréhension">listes en compréhension</a>.
</p><p>Le résultat est compilé de façon prévisible en JavaScript, et les programmes peuvent être écrits avec moins de code (typiquement un tiers de lignes en moins) sans effet sur la vitesse d'exécution<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup>. Depuis le <time class="nowrap" datetime="2011-03-16" data-sort-value="2011-03-16">16 mars 2011</time>, CoffeeScript est dans la liste des projets les plus populaires de <a href="GitHub" title="GitHub">GitHub</a><sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>.
</p><p>Le langage a une popularité relativement importante dans la communauté de Ruby. Le support de CoffeeScript est inclus dans la version 3.1 de <a href="Ruby_on_Rails" title="Ruby on Rails">Ruby on Rails</a><sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>. De plus, <a href="Brendan_Eich" title="Brendan Eich">Brendan Eich</a> a cité CoffeeScript comme une influence sur son idée du futur du JavaScript<sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup><sup class="reference cite_virgule">,</sup><sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>. En 2018, CoffeeScript est moins utilisé que dans les années précédentes, mais a largement contribué à l'évolution du langage JavaScript.
</p>

<div class="mw-heading mw-heading2"><h2 id="Histoire">Histoire</h2></div>
<p>Le <time class="nowrap date-lien" datetime="2009-12-13" data-sort-value="2009-12-13"><a href="13_d%C3%A9cembre" title="13 décembre">13</a> <a href="D%C3%A9cembre_2009" title="Décembre 2009">décembre</a> <a href="2009_en_informatique" title="2009 en informatique">2009</a></time>, Jeremy Ashkenas a effectué le premier <a href="Commit" title="Commit">commit</a> <a href="Git_(software)" class="mw-redirect" title="Git (software)">Git</a> de CoffeeScript avec le commentaire&nbsp;: «&nbsp;<i><span class="lang-en" lang="en">initial commit of the mystery language</span></i>&nbsp;» («&nbsp;premier commit du langage mystère&nbsp;»)<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup>. Le compilateur était écrit en Ruby. Le <time class="nowrap date-lien" datetime="2009-12-24" data-sort-value="2009-12-24"><a href="24_d%C3%A9cembre" title="24 décembre">24</a> <a href="D%C3%A9cembre_2009" title="Décembre 2009">décembre</a> <a href="2009_en_informatique" title="2009 en informatique">2009</a></time>, il a publié la première version numérotée et documentée, la 0.1.0. Le <time class="nowrap date-lien" datetime="2010-02-21" data-sort-value="2010-02-21"><a href="21_f%C3%A9vrier" title="21 février">21</a> <a href="F%C3%A9vrier_2010" title="Février 2010">février</a> <a href="2010_en_informatique" title="2010 en informatique">2010</a></time>, la version 0.5 a été publiée, remplaçant le compilateur Ruby par un compilateur écrit en pur CoffeeScript. <span class="need_ref" title="Une source est souhaitée pour ce passage." style="cursor:help;">À ce moment, le projet a attiré plusieurs autres contributeurs sur <a href="GitHub" title="GitHub">GitHub</a>, et les pages du site étaient vues plus de 300 fois par jour.</span><sup class="need_ref_tag" style="padding-left:2px;">[<abbr class="abbr" title="référence">réf.</abbr>&nbsp;souhaitée]</sup>
</p><p>Le <time class="nowrap date-lien" datetime="2010-12-24" data-sort-value="2010-12-24"><a href="24_d%C3%A9cembre" title="24 décembre">24</a> <a href="D%C3%A9cembre_2010" title="Décembre 2010">décembre</a> <a href="2010_en_informatique" title="2010 en informatique">2010</a></time>, Ashkenas a annoncé la publication de la version stable 1.0.0 sur <a href="Hacker_News" title="Hacker News">Hacker News</a>, le site où le projet a été annoncé pour la première fois<sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup><sup class="reference cite_virgule">,</sup><sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Exemples">Exemples</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Tests_et_compréhensions"><span id="Tests_et_compr.C3.A9hensions"></span>Tests et compréhensions</h3></div>
<p>Pour calculer l'<a href="Indice_de_masse_corporelle" title="Indice de masse corporelle">IMC</a> de Barry, joueur de basket amateur, on fait d'habitude quelque chose comme ceci (ici en <a href="JavaScript" title="JavaScript">JavaScript</a>):
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">var</span><span class="w"> </span><span class="nx">masse</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">72</span><span class="p">;</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">taille</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.86</span><span class="p">;</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">IMC</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">masse</span><span class="o">/</span><span class="nx">taille</span><span class="o">/</span><span class="nx">taille</span><span class="p">;</span>
<span class="k">if</span><span class="w"> </span><span class="p">((</span><span class="mf">18.5</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="nx">IMC</span><span class="p">)</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="p">(</span><span class="nx">IMC</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mf">25</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">alert</span><span class="p">(</span><span class="s1">'Barry a une corpulence normale'</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>CoffeeScript permet de combiner les deux tests en un seul:
</p>
<div class="mw-highlight mw-highlight-lang-coffeescript mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">masse</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">72</span>
<span class="nv">taille</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.78</span>
<span class="nv">IMC</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">masse</span><span class="o">/</span><span class="nx">taille</span><span class="o">/</span><span class="nx">taille</span>
<span class="k">if</span><span class="w"> </span><span class="mf">18.5</span><span class="o">&lt;</span><span class="nx">IMC</span><span class="o">&lt;</span><span class="mi">25</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="nx">alert</span><span class="w"> </span><span class="s">'Barry a une corpulence normale'</span>
</pre></div>
<p>ou, plus naturellement pour qui est habitué à la langue anglaise,
</p>
<div class="mw-highlight mw-highlight-lang-coffeescript mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">masse</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">72</span>
<span class="nv">taille</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.78</span>
<span class="nv">IMC</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">masse</span><span class="o">/</span><span class="nb">Math</span><span class="p">.</span><span class="nx">pow</span><span class="w"> </span><span class="nx">taille</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span>
<span class="nx">alert</span><span class="w"> </span><span class="s">'Barry a une corpulence normale'</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="mf">18.5</span><span class="o">&lt;</span><span class="nx">IMC</span><span class="o">&lt;</span><span class="mi">25</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Boucles_et_compréhensions"><span id="Boucles_et_compr.C3.A9hensions"></span>Boucles et compréhensions</h3></div>
<p>En général, l'implémentation de l'<a href="Algorithme_d'Euclide" title="Algorithme d'Euclide">algorithme d'Euclide</a> utilise une boucle <i>tant que</i> (ici, en Python)&nbsp;:
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">pgcd</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
<span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span>
<span class="k">while</span> <span class="n">y</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span> <span class="o">%</span> <span class="n">y</span>
<span class="k">return</span> <span class="n">x</span>
</pre></div>
<p>C'est également possible en CoffeeScript; mais celui-ci possède également une boucle <i>jusqu'à</i>&nbsp;:
</p>
<div class="mw-highlight mw-highlight-lang-coffeescript mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">pgcd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">(a,b) -&gt;</span>
<span class="w"> </span><span class="p">[</span><span class="nx">x</span><span class="p">,</span><span class="nx">y</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="nx">a</span><span class="p">,</span><span class="nx">b</span><span class="p">]</span>
<span class="w"> </span><span class="p">[</span><span class="nx">x</span><span class="p">,</span><span class="nx">y</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="nx">y</span><span class="p">,</span><span class="nx">x</span><span class="o">%</span><span class="nx">y</span><span class="p">]</span><span class="w"> </span><span class="k">until</span><span class="w"> </span><span class="nx">y</span><span class="w"> </span><span class="o">is</span><span class="w"> </span><span class="mi">0</span>
<span class="w"> </span><span class="nx">x</span>
</pre></div>
<p>Une boucle <i>for</i> peut souvent être remplacée par une <a href="Liste_en_compr%C3%A9hension" title="Liste en compréhension">liste en compréhension</a>. Par exemple, pour calculer les carrés des premiers nombres impairs (c'est-à-dire dont le reste modulo 2 vaut 1), on peut utiliser l'une des propositions suivantes&nbsp;:
</p>
<div class="mw-heading mw-heading4"><h4 id="Boucle_classique">Boucle classique</h4></div>
<div class="mw-highlight mw-highlight-lang-coffeescript mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="nx">n</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="p">[</span><span class="mi">1</span><span class="p">..</span><span class="mi">10</span><span class="p">]</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nx">n</span><span class="o">%</span><span class="mi">2</span><span class="w"> </span><span class="o">is</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="nx">alert</span><span class="w"> </span><span class="nx">n</span><span class="o">*</span><span class="nx">n</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="Liste_en_compréhension"><span id="Liste_en_compr.C3.A9hension"></span>Liste en compréhension</h4></div>
<div class="mw-highlight mw-highlight-lang-coffeescript mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">alert</span><span class="w"> </span><span class="p">[</span><span class="nx">n</span><span class="o">*</span><span class="nx">n</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nx">n</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="p">[</span><span class="mi">1</span><span class="p">..</span><span class="mi">10</span><span class="p">]</span><span class="w"> </span><span class="k">when</span><span class="w"> </span><span class="nx">n</span><span class="o">%</span><span class="mi">2</span><span class="w"> </span><span class="o">is</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="Avec_un_pas_de_2">Avec un pas de 2</h4></div>
<div class="mw-highlight mw-highlight-lang-coffeescript mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">alert</span><span class="w"> </span><span class="p">[</span><span class="nx">n</span><span class="o">*</span><span class="nx">n</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nx">n</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="p">[</span><span class="mi">1</span><span class="p">..</span><span class="mi">10</span><span class="p">]</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="mi">2</span><span class="p">]</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Fonctions_et_jQuery">Fonctions et <a href="JQuery" title="JQuery">jQuery</a></h3></div>
<p>Le code JavaScript permettant d'initialiser la <a href="Biblioth%C3%A8que_logicielle" title="Bibliothèque logicielle">bibliothèque</a> <a href="JQuery" title="JQuery">jQuery</a> est&nbsp;:
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// Le code d'initialisation va ici</span>
<span class="p">});</span>
</pre></div>
<p>Ou, plus simplement&nbsp;:
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// Le code d'initialisation va ici</span>
<span class="p">});</span>
</pre></div>
<p>En CoffeeScript, le mot-clé <code>function</code> est remplacé par le symbole <code>-&gt;</code>, et l'indentation est utilisée à la place des accolades, comme en <a href="Python_(langage)" title="Python (langage)">Python</a> ou en <a href="Haskell" title="Haskell">Haskell</a>. Les parenthèses peuvent généralement être omises. Ainsi, le <a href="Snippet" title="Snippet">snippet</a> ci-dessus peut être écrit, en CoffeeScript&nbsp;:
</p>
<div class="mw-highlight mw-highlight-lang-ruby mw-content-ltr" dir="ltr"><pre><span></span><span class="err">$</span><span class="p">(</span><span class="n">document</span><span class="p">)</span><span class="o">.</span><span class="n">ready</span><span class="w"> </span><span class="o">-&gt;</span>
<span class="w"> </span><span class="c1"># Le code d'initialisation va ici</span>
</pre></div>
<p>Ou bien&nbsp;:
</p>
<div class="mw-highlight mw-highlight-lang-ruby mw-content-ltr" dir="ltr"><pre><span></span><span class="err">$</span><span class="w"> </span><span class="o">-&gt;</span>
<span class="w"> </span><span class="c1"># Le code d'initialisation va ici</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Compilation">Compilation</h2></div>
<p>Le compilateur CoffeeScript est <a href="Auto-h%C3%A9bergement_(informatique)" class="mw-redirect" title="Auto-hébergement (informatique)">écrit en CoffeeScript</a> depuis la version 0.5 et est disponible en tant qu'utilitaire <a href="Node.js" title="Node.js">Node.js</a>&nbsp;; cependant, la base du compilateur ne nécessite pas <a href="Node.js" title="Node.js">Node.js</a> et peut être utilisée dans n'importe quel environnement <a href="JavaScript" title="JavaScript">JavaScript</a><sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup>. Une des alternatives à l'utilitaire <a href="Node.js" title="Node.js">Node.js</a> est <a rel="nofollow" class="external text" href="https://github.com/talios/coffee-maven-plugin">Coffee Maven Plugin</a>, un <a href="Plugin" title="Plugin">plugin</a> pour le <a href="Moteur_de_production" title="Moteur de production">moteur de production</a> <a href="Apache_Maven" title="Apache Maven">Apache Maven</a>. Ce plugin utilise <a href="Rhino_(moteur_JavaScript)" title="Rhino (moteur JavaScript)">Mozilla Rhino</a>, un <a href="Moteur_JavaScript" title="Moteur JavaScript">moteur JavaScript</a> écrit en <a href="Java_(langage)" title="Java (langage)">Java</a>.
</p><p>Le site officiel, <a rel="nofollow" class="external text" href="http://coffeescript.org">CoffeeScript.org</a>, dispose d'un bouton «&nbsp;Essayer CoffeeScript&nbsp;» dans la barre de navigation&nbsp;; cliquer dessus ouvre une <a href="Fen%C3%AAtre_modale" title="Fenêtre modale">fenêtre modale</a> qui permet d'entrer du code CoffeeScript, de voir le résultat en JavaScript, et de l'essayer directement dans le navigateur. Le site <a rel="nofollow" class="external text" href="http://js2coffee.org">js2coffee</a> propose une traduction bidirectionnelle.
</p>
<div class="mw-heading mw-heading2"><h2 id="Annexes">Annexes</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Articles_connexes">Articles connexes</h3></div>
<ul><li><a href="JavaScript" title="JavaScript">JavaScript</a></li>
<li><a href="Dart_(langage_informatique)" class="mw-redirect" title="Dart (langage informatique)">Dart</a></li>
<li><a href="Haxe" title="Haxe">Haxe</a></li>
<li><a href="TypeScript" title="TypeScript">TypeScript</a></li>
<li><a href="Pr%C3%A9processeur" title="Préprocesseur">Préprocesseur</a></li></ul>
<div class="mw-heading mw-heading3"><h3 id="Liens_externes">Liens externes</h3></div>
<ul><li><cite class="ouvrage" id="site_officiel" style="font-style: normal;"><span class="wd_p856"><a rel="nofollow" class="external text" href="https://coffeescript.org/">Site officiel</a></span></cite></li>
<li><abbr class="abbr indicateur-langue" title="Langue : anglais">(en)</abbr> <a rel="nofollow" class="external text" href="https://github.com/jashkenas/coffee-script/">Dépôt GitHub</a></li>
<li><abbr class="abbr indicateur-langue" title="Langue : anglais">(en)</abbr> <a rel="nofollow" class="external text" href="http://coffeescriptcookbook.com/">CoffeeScript Cookbook</a></li>
<li><abbr class="abbr indicateur-langue" title="Langue : anglais">(en)</abbr> <a rel="nofollow" class="external text" href="https://arcturo.github.com/library/coffeescript/">The Little Book on CoffeeScript</a></li>
<li><abbr class="abbr indicateur-langue" title="Langue : anglais">(en)</abbr> <a rel="nofollow" class="external text" href="https://autotelicum.github.com/Smooth-CoffeeScript/">Smooth CoffeeScript</a></li></ul>
<div class="mw-heading mw-heading3"><h3 id="Notes_et_références"><span id="Notes_et_r.C3.A9f.C3.A9rences"></span>Notes et références</h3></div>
<div class="references-small decimal" style=""><div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-wikidata-8a46862771c9073d71b5485985192cedb12b4b77-1"><span class="reference-text"><span class="ouvrage">«&nbsp;<a rel="nofollow" class="external text" href="https://github.com/jashkenas/coffeescript/releases/tag/2.7.0"><cite style="font-style:normal;"><span class="lang-en" lang="en">2.7.0</span></cite></a>&nbsp;», <time class="nowrap" datetime="2022-04-24" data-sort-value="2022-04-24">24 avril 2022</time> <small style="line-height:1em;">(consulté le <time class="nowrap" datetime="2022-08-09" data-sort-value="2022-08-09">9 août 2022</time>)</small></span></span>
</li>
<li id="cite_note-wikidata-5047c9576c2f60ea9af8c63e9da38a9ef8ea2876Q116058944-2"><span class="reference-text"><i>npmjs</i> (base de données en ligne), <span class="">consulté le <time class="nowrap date-lien" datetime="2023-03-01" data-sort-value="2023-03-01"><a href="1er_mars" title="1er mars">1<sup>er</sup></a> <a href="Mars_2023" title="Mars 2023">mars</a> <a href="2023" title="2023">2023</a></time>.</span></span>
</li>
<li id="cite_note-changelog-3"><span class="reference-text">The Changelog. <a rel="nofollow" class="external text" href="http://thechangelog.com/post/849754840/episode-0-2-9-coffeescript-with-jeremy-ashkenas">Épisode 0.2.9 - CoffeeScript with Jeremy Ashkenas</a> <span class="noarchive">«&nbsp;<a rel="nofollow" class="external text" href="https://web.archive.org/web/20180722151535/http://thechangelog.com/post/849754840/episode-0-2-9-coffeescript-with-jeremy-ashkenas">Copie archivée</a>&nbsp;»</span> <small>(version du <time class="nowrap" datetime="2018-07-22" data-sort-value="2018-07-22">22 juillet 2018</time> sur <i><a href="Internet_Archive" title="Internet Archive">Internet Archive</a></i>)</small>, Jul 23, 2010</span>
</li>
<li id="cite_note-smell-4"><span class="mw-cite-backlink"><a href="#cite_ref-smell_4-0">↑</a> </span><span class="reference-text"><span class="ouvrage" id="Heller2011"><span class="ouvrage" id="Martin_Heller2011"><abbr class="abbr indicateur-langue" title="Langue : anglais">(en)</abbr> Martin <span class="nom_auteur">Heller</span>, «&nbsp;<cite style="font-style:normal" lang="en">Turn up your nose at Dart and smell the CoffeeScript</cite>&nbsp;», <i><span class="lang-en" lang="en">JavaWorld</span></i>, InfoWorld,‎ <time class="nowrap" datetime="2011-10-18" data-sort-value="2011-10-18">18 octobre 2011</time> <small style="line-height:1em;">(<a rel="nofollow" class="external text" href="http://www.javaworld.com/javaworld/jw-10-2011/111018-coffeescript-vs-dart.html">lire en ligne</a>, consulté le <time class="nowrap" datetime="2012-02-09" data-sort-value="2012-02-09">9 février 2012</time>)</small><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.atitle=Turn+up+your+nose+at+Dart+and+smell+the+CoffeeScript&amp;rft.jtitle=JavaWorld&amp;rft.aulast=Heller&amp;rft.aufirst=Martin&amp;rft.date=2011-10-18&amp;rft_id=http%3A%2F%2Fwww.javaworld.com%2Fjavaworld%2Fjw-10-2011%2F111018-coffeescript-vs-dart.html&amp;rfr_id=info%3Asid%2Ffr.wikipedia.org%3ACoffeeScript"></span></span></span></span>
</li>
<li id="cite_note-wikidata-126859c26edb20d85933f02deb358e1e75771575Q124688-5"><span class="mw-cite-backlink"><a href="#cite_ref-wikidata-126859c26edb20d85933f02deb358e1e75771575Q124688_5-0">↑</a> </span><span class="reference-text"><i><a href="Black_Duck_Open_Hub" title="Black Duck Open Hub">Black Duck Open Hub</a></i> (site web), <span class="">consulté le <time class="nowrap date-lien" datetime="2018-07-18" data-sort-value="2018-07-18"><a href="18_juillet" title="18 juillet">18</a> <a href="Juillet_2018" title="Juillet 2018">juillet</a> <a href="2018" title="2018">2018</a></time>.</span></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><a href="#cite_ref-6">↑</a> </span><span class="reference-text">Read Write Hack. <span class="ouvrage"><span class="noarchive">«&nbsp;<a rel="nofollow" class="external text" href="http://www.readwriteweb.com/hack/2011/01/interview-coffeescript-jeremy-ashkenas.php"><cite style="font-style:normal; color:var(--color-link-red, #d73333);">Interview with Jeremy Ashkenas</cite></a>&nbsp;»<sup class="">(<a rel="nofollow" class="external text" href="https://web.archive.org/web/*/http://www.readwriteweb.com/hack/2011/01/interview-coffeescript-jeremy-ashkenas.php">Archive.org</a> • <a rel="nofollow" class="external text" href="https://archive.wikiwix.com/cache/?url=http://www.readwriteweb.com/hack/2011/01/interview-coffeescript-jeremy-ashkenas.php">Wikiwix</a> • <a rel="nofollow" class="external text" href="https://archive.is/http://www.readwriteweb.com/hack/2011/01/interview-coffeescript-jeremy-ashkenas.php">Archive.is</a> • <a rel="nofollow" class="external text" href="https://webcache.googleusercontent.com/search?hl=fr&amp;q=cache:http://www.readwriteweb.com/hack/2011/01/interview-coffeescript-jeremy-ashkenas.php">Google</a> • Que faire&nbsp;?)</sup></span> <small style="line-height:1em;">(consulté le <time class="nowrap" datetime="2013-04-12" data-sort-value="2013-04-12">12 avril 2013</time>)</small></span>, Jan 7, 2011</span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><a href="#cite_ref-7">↑</a> </span><span class="reference-text">Github. <a rel="nofollow" class="external text" href="https://github.com/popular/watched">Popular Watched Repositories</a> <span class="noarchive">«&nbsp;<a rel="nofollow" class="external text" href="https://web.archive.org/web/20180722151537/http://github.com/popular/watched">Copie archivée</a>&nbsp;»</span> <small>(version du <time class="nowrap" datetime="2018-07-22" data-sort-value="2018-07-22">22 juillet 2018</time> sur <i><a href="Internet_Archive" title="Internet Archive">Internet Archive</a></i>)</small></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><a href="#cite_ref-8">↑</a> </span><span class="reference-text">Peek, Joshua. <a rel="nofollow" class="external text" href="https://twitter.com/joshpeek/status/58184348742074368">Tweet by Rails Core Team Member</a> on Apr 13, 2011</span>
</li>
<li id="cite_note-9"><span class="mw-cite-backlink"><a href="#cite_ref-9">↑</a> </span><span class="reference-text">Eich, Brendan. "<a rel="nofollow" class="external text" href="http://brendaneich.com/2011/01/harmony-of-my-dreams/">Harmony of My Dreams</a>"</span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><a href="#cite_ref-10">↑</a> </span><span class="reference-text">Eich, Brendan. "<a rel="nofollow" class="external text" href="http://brendaneich.com/2011/05/my-jsconf-us-presentation/">My JSConf.US Presentation</a>"</span>
</li>
<li id="cite_note-11"><span class="mw-cite-backlink"><a href="#cite_ref-11">↑</a> </span><span class="reference-text">Github. <a rel="nofollow" class="external text" href="https://github.com/jashkenas/coffee-script/commit/8e9d637985d2dc9b44922076ad54ffef7fa8e9c2">'initial commit of the mystery language'</a></span>
</li>
<li id="cite_note-12"><span class="mw-cite-backlink"><a href="#cite_ref-12">↑</a> </span><span class="reference-text">Hacker News. <a rel="nofollow" class="external text" href="http://news.ycombinator.com/item?id=2037801">Annonce de CoffeeScript 1.0.0</a> publiée par Jeremy Ashkenas le <time class="nowrap date-lien" datetime="2010-12-24" data-sort-value="2010-12-24"><a href="24_d%C3%A9cembre" title="24 décembre">24</a> <a href="D%C3%A9cembre_2010" title="Décembre 2010">décembre</a> <a href="2010_en_informatique" title="2010 en informatique">2010</a></time></span>
</li>
<li id="cite_note-13"><span class="mw-cite-backlink"><a href="#cite_ref-13">↑</a> </span><span class="reference-text">Hacker News. <a rel="nofollow" class="external text" href="http://news.ycombinator.com/item?id=1014080">Annonce originale de CoffeeScript</a> publiée par Jeremy Ashkenas le <time class="nowrap date-lien" datetime="2009-12-24" data-sort-value="2009-12-24"><a href="24_d%C3%A9cembre" title="24 décembre">24</a> <a href="D%C3%A9cembre_2009" title="Décembre 2009">décembre</a> <a href="2009_en_informatique" title="2009 en informatique">2009</a></time></span>
</li>
<li id="cite_note-14"><span class="mw-cite-backlink"><a href="#cite_ref-14">↑</a> </span><span class="reference-text"><span class="ouvrage">«&nbsp;<a rel="nofollow" class="external text" href="http://web.archive.org/web/20130403134845/http://jashkenas.github.com/coffee-script/"><cite style="font-style:normal;">CoffeeScript</cite></a>&nbsp;», sur <span class="italique">github.com via <a href="Internet_Archive" title="Internet Archive">Internet Archive</a></span> <small style="line-height:1em;">(consulté le <time class="nowrap" datetime="2023-11-15" data-sort-value="2023-11-15">15 novembre 2023</time>)</small></span>.</span>
</li>
</ol></div>
</div>
<div class="navbox-container" style="clear:both;">


</div>
<ul id="bandeau-portail" class="bandeau-portail"><li><span class="bandeau-portail-element"><span class="bandeau-portail-icone"><span class="noviewer" typeof="mw:File"></span></span> <span class="bandeau-portail-texte">Portail des logiciels libres</span> </span></li> <li><span class="bandeau-portail-element"><span class="bandeau-portail-icone"><span class="noviewer" typeof="mw:File"></span></span> <span class="bandeau-portail-texte">Portail de la programmation informatique</span> </span></li> </ul></div><!--htdig_noindex--><div><div class="zim-footer">
Cet article est issu de <a class="external text" title="Dernière modification le 2025-03-13" href="https://fr.wikipedia.org/wiki/?title=CoffeeScript&amp;oldid=223851092">Wikipédia</a>. Sauf mention contraire, le texte est disponible sous <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.fr">Creative Commons Attribution-Share Alike 4.0</a>. Des conditions supplémentaires peuvent s’appliquer aux fichiers multimédias.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
<script src="./_webp_/webpHandler.js"></script>

</body></html>